#define _LARGEFILE64_SOURCE

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char used[50*1024];


int _get_len(int length);
int main()
{
	FILE *fd_from;
	int fd_to;
	int len, i, need, location;
	
	memset(used,0, sizeof(used));
	fd_from=fopen("query_loc.src","r");
	fd_to=open("bitmap_loc", O_RDWR| O_LARGEFILE | O_CREAT , S_IRUSR| S_IWUSR | S_IRGRP | S_IWGRP);
	
	while (fscanf(fd_from, "%d %d", &need, &location)!=EOF)
	{
		len=_get_len(need);
		for (i=location; i<location+len; i++) used[i]=-1;
		printf ("%d %d\n", len, location);
	}

	write(fd_to, used, sizeof(used));

	close(fd_to);
	fclose(fd_from);
	
	return 0;
}

int _get_len(int length)
{
	int ret=0,i;
	for (i=0; i<=15; i++)
	{
		if (length<(1<<i)) return (1<<i);
		if (length==(1<<i)) return (1<<i);
	}
	printf ("too big!%d\n",length);
	return 0;
}
